package io.renren.modules.course.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.course.entity.PlanScorePojo;
import io.renren.modules.student.entity.TeachPlanEntity;
import io.renren.modules.student.service.TeachPlanService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.course.entity.PlanScoreEntity;
import io.renren.modules.course.service.PlanScoreService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 学生成绩管理
 *
 * @author zlb
 * @email 316682546@qq.com
 * @date 2018-08-21 16:24:29
 */
@RestController
@RequestMapping("course/planscore")
public class PlanScoreController {
    @Autowired
    TeachPlanService teachPlanService;
    @Autowired
    PlanScoreService planScoreService;

    /**
     * 列表
     */
    @RequestMapping("/getListBySchoolId")
    //@RequiresPermissions("course:student:list")
    public R list(Integer id){
        PageUtils page = teachPlanService.getListBySchoolId(id);
        System.out.println(page);
        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("course:planscore:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = planScoreService.queryPage(params);

        return R.ok().put("page", page);
    }
    //planScoreList
    @RequestMapping("/planScoreList")
    public R planScoreList(@RequestParam Map<String,Object>  planScore){
        PageUtils  page = planScoreService.getListBySchoolId(planScore);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("course:planscore:info")
    public R info(@PathVariable("id") Integer id){
        PlanScoreEntity planScore = planScoreService.selectById(id);

        return R.ok().put("planScore", planScore);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("course:planscore:save")
    public R save(@RequestBody PlanScoreEntity planScore){
        planScoreService.insert(planScore);

        return R.ok();
    }

    @RequestMapping("/updateScore")
//    @RequiresPermissions("course:planscore:save")
    public R updateScore(@RequestBody PlanScoreEntity planScore){
        PlanScorePojo p=planScoreService.getOne(planScore);

        if(p!=null){
            planScore.setId(p.getId());
            planScoreService.updateAllColumnById(planScore);//全部更新
        }else {
            planScoreService.insert(planScore);
        }
        return R.ok();
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("course:planscore:update")
    public R update(@RequestBody PlanScoreEntity planScore){
        ValidatorUtils.validateEntity(planScore);
        planScoreService.updateAllColumnById(planScore);//全部更新

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("course:planscore:delete")
    public R delete(@RequestBody Integer[] ids){
        planScoreService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }


}
